﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Infra.Entity;

namespace Infra.Common.DAO
{
    public class ResouceDAL
    {
        public static void Salvar(SEGRESOUCE rs)
        {
            using (DBInfraEntityDataContext dc = new DBInfraEntityDataContext())
            {
                if (rs.CODRESOURCE != 0)
                {
                    //Alterar o utilizador
                    var R = dc.SEGRESOUCEs.Single(rSouce => rSouce.CODRESOURCE == rs.CODRESOURCE);
                    R.STRRESOURCENAME = rs.STRRESOURCENAME;
                    R.STRRESOURCEID = rs.STRRESOURCEID;
                    dc.SubmitChanges();
                }
                else
                {
                    //Gravar utilizador
                    dc.SEGRESOUCEs.InsertOnSubmit(rs);
                    dc.SubmitChanges();
                }
            }
        }

        public static void Excluir(int idResouce)
        {
            using (DBInfraEntityDataContext dc = new DBInfraEntityDataContext())
            {
                var RS = dc.SEGRESOUCEs.Single(rSouce => rSouce.CODRESOURCE == idResouce);
                dc.SEGRESOUCEs.DeleteOnSubmit(RS);
                dc.SubmitChanges();
            }
        }
    }
}
